package com.lgc.demo.biBao;

public class Main {
    public static void main(String[] args) {
        BiBao biBao = new BiBao("hehe");
        biBao.getCallbackReference().work();
    }
}

class BiBao {
    public String getName() {
        return name;
    }

    private String name;

    public BiBao(String name) {
        this.name = name;
    }

    //教学工作依然由TeachableProgrammer类定义
    private void teach() {
        System.out.println(getName() + "教师在讲台上讲解...");
    }

    private class Closure implements ITeachable {
        @Override
        public void work() {
            teach();
        }
    }

    //返回一个非静态内部类引用，允许外部类通过该非静态内部类引用来回调外部类的方法
    public ITeachable getCallbackReference() {
        return new Closure();
    }
}
